package com.example.myhelloworld.server;

import com.google.appengine.api.datastore.Key;

import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;



@PersistenceCapable(identityType = IdentityType.APPLICATION)

/**
 * UserObject - an object that holds all information tied to a user.  
 * 
 * This class is a modification of the "Employee"-class on: http://code.google.com/intl/sv/appengine/docs/java/datastore/overview.html
 * 
 */

public class UserObject {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

    @Persistent
    private String userName;

    @Persistent
    private String nickName = "";

    @Persistent
    private String userType = "student";
    
    @Persistent
    private int totalTries;
    
    @Persistent
    private int totalSuccess;
    
    @Persistent
    private String hashcode;

	@Persistent
    private String question;
    
    @Persistent
    private String hashAnswer;
    
    
    /**
    *Create a user of type "student".
    *@param name The name of the user.
    */
    public UserObject(String name, String hash, String Quest, String Answer) {
        this.userName 	= name;
        this.hashcode 	= hash;
        this.question 	= Quest;
        this.hashAnswer = Answer;
    }


//####
    public String getQuestion() {
		return question;
	}

	public String getHashAnswer() {
		return hashAnswer;
	}
  
    public String getHashCode(){
    	return hashcode; 
    }
    
    public Key getKey() {
        return key;
    }

    public String getUserName() {
        return userName;
    }
    
    public int getTotalTries() {
		return totalTries;
	}

	public void setTotalTries(int totalTries) {
		this.totalTries = totalTries;
	}

	public int getTotalSuccess() {
		return totalSuccess;
	}

	public void setTotalSuccess(int totalSuccess) {
		this.totalSuccess = totalSuccess;
	}

	/**
	 *Return the type of the user.
	 *@return Should return "student" (default), "teacher", or "admin".
	 */
	public String getUserType() {
		return userType;
	}

	/**
	 *Set the user type. Will be set to "student" if an invalid type is used.
	 *@param type "student", "teacher", or "admin".
	 */
	public void setUserType(String type) {
		if (type.equals("student") || type.equals("teacher") || type.equals("admin")) {
			userType = type;
			return;
		}
		userType = "student";
	}
	
	public boolean isValidQuestion(String hashedQuestionAnswer){
		return hashedQuestionAnswer.equals(hashAnswer);
	}
}
